#include<iostream>
using namespace std;
class CStack {
private:
	int* a;
	int size;
	int top;
public:
	CStack();
	CStack(int s);
	int get(int index);
	void push(int n);
	int isEmpty();
	int isFull();
	int pop();
	~CStack();
};
CStack::CStack() {
	a = new int[10];
	size = top = 0;
//	cout << "Constructor." << endl;
}
CStack::CStack(int s) {
	a = new int[s];
	cout << "Constructor." << endl;
}
int CStack::get(int index) {
	return a[index];
}
void CStack::push(int n) {
	a[top] = n;
	top++;
}
int CStack::isEmpty() {
	if (top==0) {
		return 1;
	}
	else {
		return 0;
	}
}
int CStack::isFull() {
	if (size == top) {
		return 1;
	}
	else {
		return 0;
	}
}
int CStack::pop() {
	top--;
	return a[top];
}
CStack::~CStack() {
	delete[] a;
	a = NULL;
	cout << "Destructor." << endl;
}
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		CStack m(n);
		int sum;
		for (int j = 0; j < n; j++) {
			cin >> sum;
			m.push(sum);
		}
		for (int j = 0; j < n; j++) {
			if (j < n - 1) {
				cout << m.pop() << ' ';
			}
			else {
				cout << m.pop() << endl;
			}
		}
	}
	return 0;
}